<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>

</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('customer/add')}">新建客户</a></li>
        <li><a href="{:url('customer/index')}">客户列表</a></li>     
    </ul>
    <form action="{:url('Customer/addPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
        <div class="row">
            <div class="col-md-9">
                <table class="table table-bordered">
                    <tr>
                        <th>客户姓名<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="text" name="post[customer_name]"
                                    required value="" placeholder="请输入客户姓名"/>
                        </td>
                    </tr>
                    
                    <tr>
                        <th>手机号码<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="text" name="post[customer_mobile]"
                                   required value="" placeholder="请输入手机号码" id='mobile'/>
                        </td>
                    </tr>

                    <tr>
                        <th>性别</th>
                        <td>
                            <input type="radio" name="post[customer_sex]"
                                  value="男" />男
                            &nbsp;&nbsp;
                            <input type="radio" name="post[customer_sex]"
                                  value="女" />女
                        </td>
                    </tr>

                 
                       
                    


                    <tr>
                        <th>QQ</th>
                        <td>
                            <input class="form-control" type="text" name="post[customer_qq]"
                                   id="title"  value="" placeholder="请输入QQ"/>
                        </td>
                    </tr>

                    <tr>
                        <th>微信</th>
                        <td>
                            <input class="form-control" type="text" name="post[customer_wx]"
                                    value="" placeholder="请输入微信"/>
                        </td>
                    </tr>
                    
                    <tr>
                        <th>邮箱</th>
                        <td>
                            <input class="form-control" type="text" name="post[customer_email]"
                                     value="" placeholder="请输入邮箱"/>
                        </td>
                    </tr>

                    <tr>
                        <th>公司职务</th>
                        <td>
                            <input class="form-control" type="text" name="post[customer_job]"
                                     value="" placeholder="请输入职务"/>
                        </td>
                    </tr>

                    <tr>
                        <th width="100">公司名称<span class="form-required"></span></th>
                        <td>
                            <input class="form-control" type="text" style="width:400px;" value=""
                                   placeholder="点击选择" onclick="company();" id='company_name' 
                                   readonly/>
                           <input type="hidden" id='company_id' name='post[company_id]'>
                        </td>
                    </tr>
                    
               

                    <tr>
                        <th width="100">项目信息<span class="form-required"></span></th>
                        <td id='project_p'>

                           <!--  <input class="form-control" type="text" style="width:400px;" value=""
                                   placeholder="点击选择" onclick="project();" id='project_name' 
                                   readonly/> -->
                          
                        </td>
                    </tr>
                   
                  
                    <tr>
                        <th>备注</th>
                        <td>
                            <script type="text/plain" id="content" name="post[desc]"></script>
                        </td>
                    </tr>
                   
                    
                </table>
                <hook name="portal_admin_article_edit_view_main"/>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
                        <a class="btn btn-default" href="{:url('AdminArticle/index')}">{:lang('BACK')}</a>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                

                <hook name="portal_admin_article_edit_view_right_sidebar"/>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });

    function company() {
        $('#project_p').html('');

        openIframeLayer("{:url('Company/find')}", '公司查找', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var all = iframeWin.confirm();

                $('#company_name').val(all.company_name);
                $('#company_id').val(all.company_id);


                //项目查找
                $.ajax({
                    type:'get',
                    url : "{:url('project/search')}?company_id="+all.company_id,
                    dataType:'json',
                    success:function(data)
                    {
                        var data = data.data;
                        if(data.length == 0)
                        {   
                            $('#project_p').html("<lable style='color:red;'>&nbsp;&nbsp;*该公司暂无项目信息,如需要则去项目管理添加<lable>");

                        }else
                        {
                            var str = '';
                            for(var i = 0;i<data.length;i++)
                            {
                                str += "<input type='checkbox' name='all_project[]' value="+data[i]['id']+"> "+data[i]['project_name']+"  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                            }
                            $('#project_p').html(str);
                        }
                    }
                })
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }

    $('#mobile').keyup(function(){
        $('#mobile_required').html(''); 
        var mobile = $(this).val();
        $.ajax({
            type:'post',
            url:"{:url('customer/search')}",
            data:{
                'mobile':mobile
            },dataType:'json',
            success:function(data)
            {
                if(data.status == 1)
                {
                    alert('手机号已存在');
                }
            }
        })
    })
    //  function project() {

    //     openIframeLayer("{:url('project/find')}", '项目查找', {
    //         area: ['700px', '400px'],
    //         btn: ['确定', '取消'],
    //         yes: function (index, layero) {

    //             var iframeWin          = window[layero.find('iframe')[0]['name']];
    //             var all = iframeWin.confirm();

    //             $('#project_id').val(all.project_id);
    //             $('#project_name').val(all.project_name);
    //             layer.close(index); //如果设定了yes回调，需进行手工关闭
    //         }
    //     });
    // }
</script>
</body>
</html>
